
/**
 * Jun 3, 2010
 * Jiadong Zhu
 * jiadong.zhu@exigenservices.com
 */

package taihootech.qa.th.loader;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertyLoader extends Loader {
	
	protected static final String SUITE = "testsuite";
	protected static final String EXCLUDED = "excluded";
	protected static final String DEFAULT = "com.taihootech.qa.testcases";
	
	private String suite = null;
	private String excluded = null;

	public PropertyLoader(ISuiteLoader iloader) {
		super(iloader);
		this.iloader = iloader;
	}///:~
	
	@Override
	public void runSuite(Object obj) {
		Properties property = null;
		
		if(obj instanceof String) {
			String path = obj.toString();
			property = new Properties();
			try {
				InputStream stream = new FileInputStream(path);
				property.load(stream);
				stream.close();
			}catch(IOException e) {
				e.printStackTrace();
			}
		}
		
		if(property == null)
			loadDefaultProperty();
		else {
			suite = property.getProperty(PropertyLoader.SUITE);
			excluded = property.getProperty(PropertyLoader.EXCLUDED);
		}
		
		this.iloader.runSuite(suite);
	}///:~
	
	private void loadDefaultProperty() {
		suite = PropertyLoader.DEFAULT;
	}///:~

}///:~ PropertyLoader Ends


